package com.xiaolin.shiro.service.impl;

import com.xiaolin.shiro.model.Member;
import com.xiaolin.shiro.model.Permission;
import com.xiaolin.shiro.model.Role;
import com.xiaolin.shiro.service.LoginService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName LoginServiceImpl
 * @Description TODO
 * @Detail detail
 * @Author MyPC
 * @Date 2020/10/8
 * @Version 1.0
 */
@Service
public class LoginServiceImpl implements LoginService{

    public static void main(String[] args) {
        LoginServiceImpl loginService=new LoginServiceImpl();
        Member member = loginService.getMemberByName("小林");
        System.out.println(member.toString());
    }

    @Override
    public Member getMemberByName(String name) {
        return selectMemberByName(name);
    }

    public Member selectMemberByName(String name){
        List<Permission> ps1=new ArrayList<>();
        List<Permission> ps2=new ArrayList<>();
        ps1.add(new Permission(1L,"select"));
        ps2.add(new Permission(1L,"select"));
        ps2.add(new Permission(2L,"add"));
        ps2.add(new Permission(3L,"update"));
        ps2.add(new Permission(4L,"delete"));
        List<Role> roles=new ArrayList<>();
        if(!StringUtils.isEmpty(name)){
            if(name.equals("哈哈")){
                roles.add(new Role(1L,"common",ps1));
            }else if(name.equals("小林")){
                roles.add(new Role(2L,"admin",ps2));
            }
        }
        return new Member(1L,"小林","123456",roles);
    }
}
